class CritPoint(list):
    def __init__(self, *args, **kwargs):
        super(CritPoint,self).__init__(*args)
        self.__id = 0
        self.__label = ''
        self.__worldCoordinates = None
        self.__properties = {}
        self.selectedPoint=[] #findNearestStructure FXN 3-22-10
        cp = kwargs.pop("point", None)
        if( cp ):
            self.extend(cp)
            self.__id = cp.getID()
            self.__label = cp.getLabel()
            self.__worldCoordinates = cp.getWorldCoordinates()
            try:
                import copy
                self.__properties = copy.deepcopy(cp._getPropertiesDict())
            except:
                pass
            
    def _getPropertiesDict(self):
        try:
            return self.__properties
        except AttributeError:
            self.__properties = {}
            return self.__properties
    def __str__(self):
        strs = "%s; "%super(CritPoint,self).__str__()
        strs += "id: %d; label: %s; "%(self.__id,self.__label)
        #strs += "wc: %s"%self.__worldCoordinates.__str__()
        return strs
    def getID(self):
        return self.__id
    def getLabel(self):
        return self.__label
    def setID(self,id):
        self.__id = int(id)
    def setLabel(self,label):
        self.__label = label
    def setWorldCoordinates(self,crds):
        self.__worldCoordinates = crds
    def getWorldCoordinates(self):
        return self.__worldCoordinates
    def setProperty(self, property, value):
        """set the property with value"""
        self.__properties[property] = value
    def getProperty(self, property, default = None):
        return self.__properties.get(property, default)
    

##    def NearestStructure(self, CritPoint, segmentPaths):
##        """When selecting a point in the image it will highlight the closest segment or structure to that point
##        crds is the location of the selected point, segmentPaths are the generated paths form the getThinningModel.py"""
##        self.mask #Mask needed for locating structures (1)
##        self.SearchPoint=CritPoint #The point selected to measure from, find nearest structure
##        neighbors=self.mask[crd[2]-1:crd[2]+2, crd[1]-1:crd[2]+2, crd[0]-1:crd[0]+2] #grab neighbors of CritPoint
##        possiblePath=[]
##        for n in range(len(neighbors)):
##            if n==1:
##                possiblePath.append(n)
##        if len(possiblePath>0):
##            for p in possiblePath:
##                for s in segmentPaths:
##                    if p==s:
##                        print "show segmentPath"
##                        print "nearest structure found"
##        else:
##            print "CritPoint not part of vessel"
##        
        
        
                        
            
        #First check to see if the point is inside the mask if not what point within the mask is closest
        #Get the neighbors of the selected point (crds)
        #Check to see if  the selected point is already in a path, if not see if any of the neighbors (7x7) of the point are within the path
        #If multiple neighbors are identified within a path calculate the distance of the neighbor from the selected point. 
        #The neighbor with the smallest distance measure is the path to highlight.
        #If no neighbors are within a segmentPath check the neighbors neighbors. Again for all the negihbors neighbors must calculate
        #the distance back to the selected point, smallest distance measure is the path to highlight.
        #Highlight the path and return the location on the viewer.
    
        
class CritPointDraw(CritPoint):
    def __init__(self, color='Red'):
        super(CritPointDraw,self).__init__()
        self.__color = color
    def __str__(self):
        strs = super(CritPointDraw,self).__str__()
        strs += "color: %s"%(self.__color)
        return strs
    def getColor(self):
        return self.__color
    def setColor(self,color):
        self.__color = color
        
